package org.zjx.common.route;


import lombok.Getter;
import lombok.Setter;
import org.zjx.common.entity.Address;

/**
 * 同城跑路
 */
@Getter
@Setter
public class RunRoute extends AbstractRoute {
    // 假设跑步速度为1秒钟/米（可根据实际需求调整）
    private static final double RUNNING_SPEED_MIN_PER_KM = 0.2;

    public RunRoute() {}
    //是否为房间内跑路
    private boolean isRoom = false;

    public RunRoute(Address startAddress, Address endAddress) {
        super(startAddress, endAddress, 0);
        if (startAddress == null || endAddress == null) throw new NullPointerException();
        if (!startAddress.getCity().equals(endAddress.getCity())) throw new IllegalArgumentException();
        if (startAddress.getX() == endAddress.getX()  && startAddress.getY() == endAddress.getY()) throw new IllegalArgumentException();
        time = calculateTime(startAddress, endAddress) + 3;
    }

    /**
     * 计算跑步所需时间（分钟）
     * @param start 起点坐标
     * @param end 终点坐标
     * @return 计算得到的时间（四舍五入取整）
     */
    private static int calculateTime(Address start, Address end) {
        // 计算坐标差值
        double deltaX = end.getX() - start.getX();
        double deltaY = end.getY() - start.getY();

        // 计算直线距离（公里）
        double distanceKm = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));

        // 转换为时间（分钟）并四舍五入
        return (int) Math.round(distanceKm * RUNNING_SPEED_MIN_PER_KM);
    }
}
